package com.example.component.a_activity

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.component.util.LifecycleActivity
import com.example.component.a_activity.intent.ASecondActivity
import com.example.component.util.BaseActivity
import com.example.component.R
import com.example.component.data.User

class AFirstActivity : LifecycleActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_a_first)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val button = findViewById<Button>(R.id.explicit)
        val button2 = findViewById<Button>(R.id.implicit)

        val user = User(
            id = "12345",
            name = "John Doe",
            email = "averych@126.com"
        )

        button.setOnClickListener {
            // 显式跳转
            val intent = Intent(this, ASecondActivity::class.java)
            // 传递数据
            intent.putExtra("user", user)
            startActivity(intent)
        }

        button2.setOnClickListener {
            // 隐式跳转
            val intent02 = Intent()
            intent02.action = "com.example.activity.IMPLICIT_ACTION_START"
            intent02.addCategory("com.example.activity.MY_CATEGORY")
            startActivity(intent02)
        }
    }
}